class Solution {
public:
    int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
        int n = gas.size();
        for(int i = 0; i < n; ++i)
        {
            int diff = 0, step = 0;
            for(; step < n; ++step)
            {
                int index = (i + step) % n; // 求出⾛ step 步之后的下标
                diff += gas[index] - cost[index];
                if(diff < 0)
                    break;
            }
            if(diff >= 0) // 正常跳出
                return i;
        }
        return -1;
    }
};